﻿namespace Web.Control.WWW.Lesson
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Model.WWW_User.Teach;
    using BLF.WWW_User.Teach;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using System.Collections.Generic;
    using Model.WWW_User.User;
    public class Alesson : BaseControl
    {   
        /// <summary>
        /// 登陆的会员号
        /// </summary>
        protected string memberno = "";
        /// <summary>
        /// lesson id
        /// </summary>
        protected string lid;
        /// <summary>
        /// couresmodel 其中的Sessions和Views都为lesson、
        /// </summary>
        protected CoursesModel cm=new CoursesModel();
        /// <summary>
        /// 其中的0为是否验证为老师,1是否禁用
        /// </summary>
        protected List<bool> bllist;
        /// <summary>
        /// tag 列表
        /// </summary>
        protected List<string> taglist;
        /// <summary>
        /// 时间
        /// </summary>
        protected List<string> strlist;
        /// <summary>
        /// 该会员的总sessions数
        /// </summary>
        protected int asession = 0;
        /// <summary>
        /// 该coures的lesson
        /// </summary>
        protected List<LessonModel> lmlist1;
        /// <summary>
        /// 该会员的Courses
        /// </summary>
        protected List<CoursesModel> cmlist;
        /// <summary>
        /// 相关的lesson
        /// </summary>
        protected List<LessonModel> lmlist2;
        protected List<long> lglist;
        protected LessonModel lm = null;
        protected Repeater repless;
        protected Repeater repcour;
        protected Repeater repless2;
        protected List<UserTimeAvailability> TimeAvaila=new List<UserTimeAvailability>();
        protected string timezone = "";

        protected override void OnLoad(EventArgs e)
        {
            memberno = HttpContext.Current.User.Identity.Name;
            ArrayList arrlist = new ArrayList();
            if (!string.IsNullOrEmpty(Request["lid"]))
            {
                lid = Request["lid"];
            }
            else
            {
                Response.End();
            }
            string sessionID = "";
            string iP = "";
            string userAgent = "";
            string referer = "";
            sessionID = Session.SessionID;
            iP = Request.UserHostAddress;
            userAgent = Request.UserAgent;
            referer = HttpContext.Current.Request.UrlReferrer == null ? "" : HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
            arrlist=Teach.GetALessonInfo(memberno, lid, sessionID, iP, userAgent, referer);
            if (arrlist == null||arrlist.Count<5)
            {
                Response.End();
                return;
            }
            cm = arrlist[0] as CoursesModel;
            bllist = arrlist[1] as List<bool>;
            taglist = arrlist[2] as List<string>;
            asession = (int)arrlist[3];
            lmlist1=arrlist[4] as List<LessonModel>;
            cmlist=arrlist[5] as List<CoursesModel>;
            lmlist2=arrlist[6] as List<LessonModel>;
            lm = arrlist[7] as LessonModel;
            lglist = arrlist[8] as List<long>;
            timezone = (string)arrlist[10];
            TimeAvaila = BLF.WWW_User.Teach.Teach.UserTimeAvaila(arrlist[9] as List<UserTimeAvailability>, arrlist[10].ToString());
            if (repless != null)
            {
                repless.DataSource = lmlist1;
                repless.DataBind();
            }
            if (repcour != null)
            {
                repcour.DataSource = cmlist;
                repcour.DataBind();
            }
            if (repless2 != null)
            {
                repless2.DataSource = lmlist2;
                repless2.DataBind();
            }
            //title
            this.DynamicTitle = GetText("{0} - italki {1} Lessons", new string[] { lm.Title, BLF.StaticData.GetLanguageText(cm.LanguageLearn) });
            this.DynamicKeywords = GetText("{0}, lesson, {1}", new string[] { lm.Title, BLF.StaticData.GetLanguageText(cm.LanguageLearn) });
            this.DynamicDescription = Lx.Web.Common.UI.Globals.GetString(lm.Desc, 150);
            base.OnLoad(e);
        }

        /// <summary>
        /// 获取课件使用语言文本
        /// </summary>
        /// <param name="value">课件baselanguage</param>
        /// <returns>页面所需文本</returns>
        protected string GetBaseLanText(string value)
        {
            System.Text.StringBuilder strApp = new System.Text.StringBuilder();
            string[] arrStr = value.Split('|');
            int len = arrStr.Length;
            for (int i = 0; i < len; i++)
            {
                strApp.Append(GetText("C2018", new string[] { arrStr[i] }));
                strApp.Append(",");
            }
            return strApp.ToString().Remove(strApp.ToString().Length - 1);
        }
    }
}